<template>
	<view class="appUpdateMask" style="border: 2px solid red;">
		<view class="appUpdateContent">

		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {

			}
		},
		onShow() {
			// this.$nextTick(function() {
			// 	this.$refs.popup.open()
			// })

		},
		methods: {
			openform() {
				this.$refs.popup.open()
			},
			//拍照和相册选择
			upclick(type) {
				var that = this
				let sourceType = ""
				if (type === '拍照') {
					sourceType = "camera"
					setTimeout(() => {
						that.$refs['AuthCamera'].open();
					}, 500)
				} else {
					sourceType = "album"
					setTimeout(() => {
						that.$refs['AuthPhoto'].open();
					}, 500)
				}

				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: [sourceType], //这要注意，camera掉拍照，album是打开手机相册
					success: (result) => {
						console.log('获取选中的图片结果--', result.tempFilePaths[0])
						uni.showLoading({
							title: '上传中..'
						})
						uni.uploadFile({
							url: this.$ActionUrl + '/Base_Manage/Base_User/UploadFileByForm',
							filePath: result.tempFilePaths[0],
							header: {
								'Authorization': 'Bearer' + ' ' + uni.getStorageSync('token')
							},
							name: 'file',
						}).then(resJson => {
							let [err, res] = [...resJson]
							// console.log('获取上传成功后的的结果', err, res)
							if (res.errMsg === 'uploadFile:ok') {
								let fileData = JSON.parse(res.data)
								if (fileData.url) {
									this.UserInfo.UserInfo.UserAvatarURL = fileData.url
									console.log('赋值后的url', this.UserInfo.UserInfo)
									// 保存头像
									this.setBase_UserUpdateDataByConditions()

									this.$forceUpdate()
									// 说明上传成功
									this.$sucessToast('已上传')
									uni.hideLoading()

								} else {

									this.$errorToast(fileData.Msg)
									uni.hideLoading()
								}
							}
							// if (err !== null) return uni.showToast({
							// 	icon: 'none',
							// 	title: '网络连接失败,请重试'
							// })
							// this.save(JSON.parse(res.data).Url)
						})
					}
				});
				that.$refs.popup.close()
			},
		}
	}
</script>

<style>
	page {
		background: transparent;
	}

	.appUpdateMask {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
		background-color: rgba(0, 0, 0, 0.4);
	}

	.appUpdateContent {
		width: 80vw;
		height: 40vh;
		border-radius: 20rpx;
		background-color: white;
		justify-content: space-around;
		align-items: flex-start;
	}
</style>